﻿namespace Core
{
    using System;
    using Contracts.Enums;
    using Contracts.Interfaces;
    using Resources;
    using System.Globalization;

    /// <summary>
    /// Feature modifier class
    /// </summary>
    public class Modifier : IModifier
    {
        private FeatureTypesEnum _modifiedFeatureType;
        private FeaturesEnum _feature;
        private ModuleActivationTypesEnum _activationState;
        private double _value;
        private UnitsEnum _displayUnit;
        private string _displayName;
        private bool _isVisible = true;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:Core.Modifier"/> class.
        /// </summary>
        public Modifier(){ }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Core.Modifier"/> class.
        /// </summary>
        public Modifier(FeatureTypesEnum modifiedFeatureType, FeaturesEnum feature, double value)
        {
            ModifiedFeatureType = modifiedFeatureType;
            Feature = feature;
            Value = value;
        }

        /// <summary>
        /// Obtains or defines if the modifier should be displayed (e.g : Robot mass module modifier )
        /// Default is true
        /// </summary>
        public virtual bool IsVisible
        {
            get {  return _isVisible; }
            set { _isVisible = value; }
        }

        /// <summary>
        /// Obtains the modifier display name
        /// </summary>
        public virtual string DisplayName
        {
            get { return String.IsNullOrEmpty(_displayName) ? _feature.ToString() : _displayName; }
            set { _displayName = value; }
        }

        /// <summary>
        /// Obtains or defines the displayed value unit
        /// </summary>
        public UnitsEnum Unit
        {
            get { return _displayUnit; }
            set { _displayUnit = value; }
        }

        /// <summary>
        /// Obtains or defines the modified feature type
        /// </summary>
        public FeatureTypesEnum ModifiedFeatureType
        {
            get { return _modifiedFeatureType; }
            set { _modifiedFeatureType = value; }
        }

        /// <summary>
        /// Obtains or defines the modified feature
        /// </summary>
        public FeaturesEnum Feature
        {
            get { return _feature; }
            set { _feature = value; }
        }

        /// <summary>
        /// Obtains or defines the modifier value
        /// </summary>
        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }
        /// <summary>
        /// Obtains the formatted value
        /// </summary>
        public string FormattedValue
        {
            get
            {
                string text = null;
                switch (_displayUnit)
                {
                    default :
                        text = string.Format(CultureInfo.CurrentCulture, "{0}", Value);
                        break;
                    case UnitsEnum.Percentage :
                        text = string.Format(CultureInfo.CurrentCulture, "{0:P0}", Value);
                        break;
                    case UnitsEnum.AccumulatorPoints :
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_AP);
                        break;
                    case UnitsEnum.Degree :
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_degree);
                        break;
                    case UnitsEnum.Hitpoints :
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_hp);
                        break;
                    case UnitsEnum.Mass :
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_kg);
                        break;
                    case UnitsEnum.Meters :
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_meters);
                        break;
                    case UnitsEnum.Speed:
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_speed);
                        break;
                    case UnitsEnum.Time:
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_sec);
                        break;
                    case UnitsEnum.Points:
                        text = string.Format(CultureInfo.CurrentCulture, "{0} {1}", Value, Traduction.label_unit_points);
                        break;
                }
                return text;
            }
        }

        /// <summary>
        /// Obtains or defines the state of the module has to be to apply the modification
        /// </summary>
        public ModuleActivationTypesEnum ActivationState
        {
            get { return _activationState; }
            set { _activationState = value; }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            return DisplayName;
        }
    }
}